package com.matrix.java.chap_03;

import java.util.Scanner;

/*
    几何：交点
 */
public class Ex3_25 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter x1, y1, x2, y2, x3, y3, x4, y4: ");
        float x1 = input.nextFloat();
        float y1 = input.nextFloat();
        float x2 = input.nextFloat();
        float y2 = input.nextFloat();
        float x3 = input.nextFloat();
        float y3 = input.nextFloat();
        float x4 = input.nextFloat();
        float y4 = input.nextFloat();
        //****************
        float a = y1 - y2;
        float b = x1 - x2;
        float e = (y1 - y2) * x1 - (x1 - x2) * y1;
        float c = y3 - y4;
        float d = x3 - x4;
        float f = (y3 - y4) * x3 - (x3 - x4) * y3;

        if (a * d == b * c) {
            System.out.println("The two lines are parallel");
        } else {
            float x = (e * d - b * f) / (a * d - b * c);
            float y = (a * f - e * c) / (a * d - b * c);
            System.out.println("The intersecting point is at (" + x + ", " + y + ")");
        }
    }
}
